/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.cggveritas.crewintranet.migrationdb.sqlserver;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;



/**
 *
 * @author Chitou
 */
public class TestConnexionSGBDSqlServer {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        
            Connection con = null;
            
            
            try {
                 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver" );
                 String connectionString ="jdbc:sqlserver://127.0.0.1:34500;database=FleetManager;user=SA;password=aissatou1";
                 con = DriverManager.getConnection(connectionString);
                 Statement test = con.createStatement();
                 
//          Ajout des vehicules
                 test.execute("select iVehicleID, liSiteID,liGroupID,sDesc,sRegNo,"
                         + "dtLastUpdate,dtLastTrip from Vehicles order by liSiteID,liGroupID ");
                 
                ResultSet res = test.getResultSet();

                
//                test.execute("select liGroupID , sName from Sites");
//                ResultSet res = test.getResultSet();
                List V1= new ArrayList<VehicleDataSS>(); 
                while (res.next()) {
                
                VehicleDataSS V= new VehicleDataSS(
                        res.getString("iVehicleID"), 
                        res.getString("liSiteID"),
                        res.getString("liGroupID"),
                        res.getString("sDesc"),
                        res.getString("sRegNo"), 
                        res.getDate("dtLastUpdate"), 
                        res.getDate("dtLastTrip"));
                        
                
                V1.add(V);
                
     }

     //          Ajout des groupes           
                test.execute("select liGroupID , sName from VehicleConfig");
                ResultSet res1 = test.getResultSet();
                List G1= new ArrayList<GroupeDataSS>(); 
                while (res1.next()) {
                
                GroupeDataSS G= new GroupeDataSS(
                        res1.getString("liGroupID"), 
                        res1.getString("sName"));
                        
                
                G1.add(G);
                
     }

        
//          Ajout des sites   
                
                test.execute("select liGroupID , sName from VehicleConfig");
                ResultSet res2 = test.getResultSet();
                List S1= new ArrayList<SitesDataSS>(); 
                while (res2.next()) {
                
                SitesDataSS S= new SitesDataSS(
                        res2.getString("liGroupID"), 
                        res2.getString("sName"));
                        
                
                S1.add(S);
                
     }
                
                
                
                
                
    }
        catch (Exception e) {
            System.err.println("Exception: " + e.getMessage());
        }
    }
        public static void migrationDataBaseSS(List<VehicleDataSS> VList) throws Exception {
        try {
            
        } catch (Exception e) {
            System.err.println("Exception : " + e.getMessage());
        }

    }
            
            
}

